package IOStreamStudy.inputStream;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * FileInPutStream 使用
 * 字节输入流   文件-->程序
 * */
public class FileInPutStreamDemo {

    @Test
    public void readFile() throws IOException {
        String filePath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\a.txt";
        FileInputStream fileInputStream = new FileInputStream(filePath);
        int readData;//
        while ((readData = fileInputStream.read())!=-1){
            //fileInputStream.read()每次读取一个byte,将读到的bit转化成对应十进制值.
            // 这样没去只取一个的效率不高
            System.out.println((char) readData);
            System.out.println(readData);
        }
        fileInputStream.close();

    }

    @Test
    public void readFile02() throws IOException {
        String filePath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\a.txt";
        FileInputStream fileInputStream = new FileInputStream(filePath);
        byte[] buffer = new byte[8];
        int len;
        while ((len = fileInputStream.read(buffer))!=-1){
            // 每次读取一个字节数组
            System.out.println(new String(buffer,0,len));
            System.out.println(len);
        }
        fileInputStream.close();

    }


}
